package com.itheima.myscoket.test81;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建一个线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,//核心线程数
                10,//最大线程数
                60,//临时线程空闲时间
                TimeUnit.SECONDS,//临时线程时间单位
                new ArrayBlockingQueue<>(5),//阻塞队列
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.AbortPolicy()//拒绝任务
        );
        //接收端口
        ServerSocket ss = new ServerSocket(10086);
        //将服务器循环挂起
        while (true) {
            //接收网络中的流
            Socket accept = ss.accept();
               MyRunable mr = new MyRunable(accept);
//               Thread t = new Thread(mr);
//               t.start();
            pool.submit(mr);

        }
        //ss.close();
    }
}
